<template>
  <div class="page-container page-container-create">
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>营销中心</el-breadcrumb-item>
        <el-breadcrumb-item>通用促销</el-breadcrumb-item>
        <el-breadcrumb-item>创建满量促销</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <p class="font22 mb20">创建满量促销</p>
    
    <div class="stepset" >
      <ul>
        <li :class="{'active':active>=0}"><span>1</span><p>设置活动规则</p></li>
        <li :class="{'active':active>=1}"><span>2</span><p>设置活动商家/店铺</p></li>
        <li :class="{'active':active>=2}"><span>3</span><p>设置活动商品</p></li>
        <li :class="{'active':active>=4}"><span>4</span><p>创建成功</p></li>
      </ul>
    </div>

    <div v-if="active == 0" class="content createSet create_stepOne create_stepAlso">
      <el-form
        :inline="true"
        :model="dataForm"
        :rules="dataFormRules"
        ref="dataForm"
        :label-position="labelPosition"
      >
        <div class="w100">
          <div class="title">基本信息：</div>
          <div class="item">
            <el-row class="m_b30">
              <el-form-item label="活动名称：" prop="promName" class="wid t_r" label-width="122px">
                <el-input
                  type="text"
                  v-model="dataForm.promName"
                  placeholder="请输入3-60个字符之间"
                  maxlength="60"
                  minlength="3"
                  size="mini"
                  clearable
                  class="input"
                />
              </el-form-item>
            </el-row>

            <el-row class="m_b30">
              <el-form-item label="活动时间：" prop="SeckillTime" class="wid t_r" label-width="122px">
                <el-date-picker
                  v-model="dataForm.SeckillTime"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  size="mini"
                  @change="SeckillTimeChanage"
                  :picker-options="timeCheck"
                ></el-date-picker>
              </el-form-item>
            </el-row>

            <el-row class="m_b30">
              <el-form-item label="活动标签：" prop="tags" class="wid t_r" label-width="122px">
                <el-select v-model="dataForm.label" placeholder="请选择" size="mini">
                  <el-option
                    v-for="item in tagsList"
                    :key="item.id"
                    :label="item.tagName"
                    :value="item.id"
                  ></el-option>
                </el-select>
                <el-button type="primary" @click="addtags" size="mini">添加标签</el-button>
              </el-form-item>
            </el-row>

            <el-row class="m_b60 labelAlignment">
              <el-form-item label="店铺地区：" prop="storeCode" class="wid t_r" label-width="122px">
                <el-radio v-model="dataForm.storeCode" label="0" value="0">全国</el-radio>
              </el-form-item>
            </el-row>
          </div>
        </div>

        <div class="w100">
          <div class="title">活动规则：</div>
          <div class="item">
            <el-row class="m_b30 labelAlignment">
              <el-form-item label="促销类型：" prop="frontPromType" class="wid t_r" label-width="122px">
                <el-radio-group v-model="dataForm.frontPromType" @change="changeDescriptions">
                  <el-radio class="m_r45 form-radio radioAlignmentSpecial" label="2001" value="2001">满量减</el-radio>
                  <el-radio class="m_r45 form-radio radioAlignmentSpecial" label="2002" value="2002">满量折</el-radio>
                  <el-radio class="form-radio radioAlignmentSpecial m_r30" label="2003" value="2003">满量减运费</el-radio>
                </el-radio-group>
                <div v-if="dataForm.frontPromType == '2003'" class="f-r">
                  <el-radio v-model="dataForm.reduceFreight" label="1" value="1" class="m_r20">
                    满
                    <el-input v-model="dataForm.numberOfPieces" :size="size" clearable class="parentPlatformRatio"></el-input>件，免运费
                  </el-radio>
                  <el-radio v-model="dataForm.reduceFreight" label="2" value="2">
                    满
                    <el-input v-model="dataForm.numberOfPiecesTwo" :size="size" clearable class="parentPlatformRatio"></el-input>件，
                    减
                    <el-input :size="size" v-model="dataForm.freight" clearable class="parentPlatformRatio"></el-input>元运费
                  </el-radio>
                </div>
              </el-form-item>
            </el-row>

            <el-row class="m_b30 labelAlignment">
              <el-form-item label="是否叠加应用：" prop="overlayAppNum" class="wid">
                <el-radio
                  class="m_r45 form-radio radioAlignment"
                  v-model="dataForm.overlayAppNum"
                  label="0"
                  value="0"
                >否（超量：按最高层级享受优惠）</el-radio>
                <el-radio
                  class="form-radio radioAlignment"
                  v-model="dataForm.overlayAppNum"
                  label="1"
                  value="1"
                >
                  是（倍量：每满一级优惠一次）
                  <span v-if="dataForm.overlayAppNum == '1'">
                    上限
                    <el-input
                      :size="size"
                      v-model="dataForm.limitNum"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      class="parentPlatformRatio one"
                    ></el-input>
                    <span class="m_l10">次</span>
                  </span>
                </el-radio>
              </el-form-item>
            </el-row>

            <el-row class="labelAlignment" v-if="dataForm.frontPromType != '2003'">
              <el-form-item label="优惠设置：" class="wid labelAlignment vt " prop="overlayAppNum" label-width="122px">
                <div class="disCountSet disCountSetTwo">
                  <!-- 静态table表格 -->
                  <el-table :data="dataForm.fullNumCouponInfoList" border class="stepOne_table">
                    <el-table-column prop="couponSetindex" align="center" label="优惠阶梯" width="100">
                      <template slot-scope="scope">
                        <label>{{ scope.row.level }}</label>
                      </template>
                    </el-table-column>
                    <el-table-column prop="content" align="center" label="优惠门槛" width="308">
                      <template slot-scope="scope" class="conditionValue">
                        <div class="flex">
                          <el-form-item>
                            <span class="disCountSetLabel">满</span>
                            <el-input
                              v-model="scope.row.goodsNum"
                              placeholder="X"
                              :size="size"
                              oninput="value=value.replace(/[^\d]/g,'')"
                              clearable
                            ></el-input>
                          </el-form-item>
                          <span
                            class="disCountSetLabel"
                            v-if="dataForm.frontPromType == '2002'"
                          >件, 打</span>
                          <span
                            class="disCountSetLabel"
                            v-if="dataForm.frontPromType == '2001'"
                          >件, 减</span>
                          <el-form-item>
                            <el-input
                              v-model="scope.row.goodsPrice"
                              placeholder="Y"
                              :size="size"
                              oninput="value = value.match(/^\d*(\.?\d{0,2})/g)[0]"
                              clearable
                            ></el-input>
                          </el-form-item>
                          <span class="disCountSetLabel" v-if="dataForm.frontPromType=='2002'">折</span>
                          <span class="disCountSetLabel" v-if="dataForm.frontPromType=='2001'">元</span>
                        </div>
                      </template>
                    </el-table-column>

                    <el-table-column prop="explain" align="center" label="优惠说明" width="180">
                      <template slot-scope="scope">
                        <label>
                          <span>满</span>
                          {{scope.row.goodsNum}}件,
                          <span
                            v-if="dataForm.frontPromType == '2002'"
                          >打</span>
                          <span v-if="dataForm.frontPromType == '2001'">减</span>
                          {{scope.row.goodsPrice}}
                          <span
                            v-if="dataForm.frontPromType == '2002'"
                          >折</span>
                          <span v-if="dataForm.frontPromType == '2001'">元</span>
                          ;
                        </label>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="100">
                      <template slot-scope="scope">
                        <el-button
                          v-if="scope.$index != 0"
                          size="mini"
                          type="text"
                          @click="removePromotionRuleSet(scope.$index, scope.row)"
                        >删除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-button
                    size="mini"
                    type="primary"
                    @click="addPromotionRuleSet"
                    :disabled="dataForm.fullNumCouponInfoList.length >= 5 ? true : false"
                  >新增优惠</el-button>
                </div>
              </el-form-item>
            </el-row>

            <el-row class="labelAlignment">
              <el-form-item label="活动描述：" class="wid activityDesc t_r" label-width="122px">
                <el-input
                  class="activityDesc remarks"
                  type="textarea"
                  :size="size"
                  v-model="dataForm.chineseDesc"
                  :placeholder="descriptions"
                  clearable
                ></el-input>
              </el-form-item>
            </el-row>

            <el-row>
              <el-form-item label class="wid">
                <div
                  class="desc color666"
                >注：非必填字段，不填将显示系统默认文案（会存在某些促销类型无系统默认文案）。自定义输入活动规则描述描述后将显示在前台商品详情页中，请慎重填写。</div>
              </el-form-item>
            </el-row>
          </div>
        </div>

        <div class="w100">
          <div class="title">交易规则：</div>
          <div class="item">
            <el-row class="m_b52 labelAlignment" v-if="dataForm.type != '3'">
              <el-form-item label="是否包邮：" class="wid t_r" label-width="122px">
                <el-radio-group v-model="dataForm.parcelsFlag">
                  <el-radio class="form-radio m_r45 radioAlignment" label="1" value="1">是</el-radio>
                  <el-radio class="form-radio radioAlignment" label="0" value="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-row>

            <el-row class="m_b60 ways labelAlignment">
              <el-form-item label="是否分摊：" prop="costAllocationFlag" class="wid t_r" label-width="122px">
                <el-row class="m_b52">
                  <el-radio-group v-model="dataForm.costAllocationFlag" prop="costAllocationFlag">
                    <el-radio
                      class="form-radio m_r45 radioAlignment"
                      v-model="dataForm.costAllocationFlag"
                      label="1"
                      checked="true"
                      name="type"
                      value="1"
                    >是</el-radio>
                    <el-radio
                      class="form-radio radioAlignment"
                      v-model="dataForm.costAllocationFlag"
                      label="2"
                      name="type"
                      value="2"
                    >否</el-radio>
                  </el-radio-group>
                </el-row>
                <div v-if="dataForm.costAllocationFlag == '1'" class="rates">
                  <span v-if="dataForm.costAllocationFlag == '1' && deptType == 0">母平台比例：</span>
                  <el-form-item
                    prop="parentAllocationScale"
                    v-if="dataForm.costAllocationFlag == '1' && deptType == 0"
                  >
                    <el-input
                      v-model.trim="dataForm.parentAllocationScale"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      auto-complete="off"
                      type="text"
                      :size="size"
                      class="parentPlatformRatio"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span class="m_r16" v-if="dataForm.costAllocationFlag == '1' && deptType == 0">%</span>

                  <span v-if="dataForm.costAllocationFlag == '1' && (deptType == 0 || deptType == 1)">子平台比例：</span>
                  <el-form-item
                    prop="childAllocationScale"
                    v-if="dataForm.costAllocationFlag == '1' && (deptType == 0 || deptType == 1)"
                  >
                    <el-input
                      v-model.trim="dataForm.childAllocationScale"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      auto-complete="off"
                      type="text"
                      :size="size"
                      class="parentPlatformRatio"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span class="m_r16" v-if="dataForm.costAllocationFlag == '1' && (deptType == 0 || deptType == 1)">%</span>
                  
                  <span v-if="dataForm.costAllocationFlag == '1' && (deptType == 1 || deptType == 2)">商家比例：</span>
                  <el-form-item
                    prop="merchantAllocationScale"
                    v-if="dataForm.costAllocationFlag == '1' && (deptType == 1 || deptType == 2)"
                  >
                    <el-input
                      v-model.trim="dataForm.merchantAllocationScale"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      auto-complete="off"
                      type="text"
                      :size="size"
                      class="parentPlatformRatio"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span class="m_r16" v-if="dataForm.costAllocationFlag == '1' && (deptType == 1 || deptType == 2)">%</span>

                  <span v-if="dataForm.costAllocationFlag == '1' && (deptType == 2 || deptType == 3)">店铺比例：</span>
                  <el-form-item
                    prop="merchantAllocationScale"
                    v-if="dataForm.costAllocationFlag == '1' && (deptType == 2 || deptType == 3)"
                  >
                    <el-input
                      v-model.trim="dataForm.storeAllocationScale"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      auto-complete="off"
                      type="text"
                      :size="size"
                      class="parentPlatformRatio"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span class="m_r16" v-if="dataForm.costAllocationFlag == '1' && (deptType == 2 || deptType == 3)">%</span>
                </div>
              </el-form-item>
            </el-row>
          </div>
        </div>

        <div class="w100">
          <div class="title">参与条件：</div>
          <div class="item">
            <el-row class="m_b30">
              <el-form-item label="新老用户：" prop="proUserType" class="wid ways labelAlignment t_r" label-width="122px">
                <el-radio
                  class="m_r45 radioAlignment"
                  v-model="dataForm.proUserType"
                  label="0"
                  value="0"
                >不限制</el-radio>
                <el-radio
                  class="m_r45 radioAlignment"
                  v-model="dataForm.proUserType"
                  label="2"
                  value="2"
                >老用户</el-radio>
                <el-radio
                  class="m_r45 radioAlignment"
                  v-model="dataForm.proUserType"
                  label="1"
                  value="1"
                >新用户</el-radio>
              </el-form-item>
            </el-row>

            <el-row v-if="deptType == 0" class="m_b52 ways labelAlignment" >
              <el-form-item label="使用渠道：" class="wid t_r" required label-width="122px">
                <el-tree
                  :data="channelList"
                  :props="channlProps"
                  show-checkbox
                  node-key="id"
                  :default-expand-all="true"
                  ref="channelTree"
                  @check="channelIdsChange"
                ></el-tree>
              </el-form-item>
            </el-row>

            <el-row>
              <el-form-item label="备注：" class="wid remarks-editor t_r" label-width="122px">
                <el-input
                  type="textarea"
                  ref="text"
                  v-model="dataForm.remark"
                  class="remarks"
                  :options="editorOption"
                />
              </el-form-item>
            </el-row>
          </div>
        </div>
      </el-form>
    </div>

    <div v-if="active == 1" class="tab-container createSet tab-container-noPadding">
      <el-tabs v-model="activeName" type="border-card">
        <el-tab-pane label="商家" name="1">
          <el-row class="search-button-fix t_r">
            <el-row>
              <el-button type="primary" @click="addMerchant">添加商家</el-button>
              <el-button type="primary" @click="batchDeleteMerchant">批量删除</el-button>
            </el-row>
          </el-row>
          <div class="table-section">
            <el-table
              :data="tableData"
              :header-cell-style="tableHeaderColor"
              ref="multipleTable"
              style="width: 100%"
              :row-class-name="tableRowClassName"
              border
              :size="size"
              @selection-change="selectMerchantChange"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column v-if="false" prop="merchantId"></el-table-column>
              <el-table-column prop="orgNumber" label="商家编码" sortable align="center"></el-table-column>
              <el-table-column prop="name" label="商家名称" align="center"></el-table-column>
              <el-table-column prop="merchantType" label="组织分类" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.merchantType == '1'">自营商家</span>
                  <span v-else-if="scope.row.merchantType == '2'">第三方商家</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" fixed="right" align="center">
                <template slot-scope="scope">
                  <el-button
                    :size="size"
                    type="text"
                    @click="handleDelete(scope.$index, scope.row)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div v-if="tableData.length > 0" class="t_r">
            <el-pagination
              @size-change="merchantSizeChange"
              @current-change="merchantCurrentChange"
              :current-page="merchantStaticDataForm.start"
              :page-sizes="[10]"
              :page-size="merchantStaticDataForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="merchantTotal"
            ></el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane label="店铺" name="2">
          <el-row class="search-button-fix t_r">
            <el-button type="primary" @click="addStore">添加店铺</el-button>
            <el-button type="primary" @click="batchDeleteStore">批量删除</el-button>
          </el-row>
          <div class="table-section">
            <el-table
              :data="storeTableData"
              :header-cell-style="tableHeaderColor"
              ref="multipleTable"
              style="width: 100%"
              :row-class-name="tableRowClassName"
              border
              :size="size"
              @selection-change="selectStoreChange"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column v-if="false" prop="storeId">
                <template slot-scope="scope">
                  <div :model="scope.row.id"></div>
                </template>
              </el-table-column>
              <el-table-column prop="storeCode" label="店铺编码" sortable align="center"></el-table-column>
              <el-table-column prop="storeName" label="店铺名称" align="center"></el-table-column>
              <el-table-column label="操作" fixed="right" align="center">
                <template slot-scope="scope">
                  <el-button
                    :size="size"
                    type="text"
                    @click="handleDeleteStore(scope.$index, scope.row)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div v-if="storeTableData.length > 0" class="t_r">
            <el-pagination
              @size-change="storeSizeChange"
              @current-change="storeCurrentChange"
              :current-page="storeStaticDataForm.start"
              :page-sizes="[10]"
              :page-size="storeStaticDataForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="storeTotal"
            ></el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div v-if="active == 2" class="tab-container createSet active3">
      <div class="row-line-button">
        <el-button type="primary" plain size="mini" v-if="skuTotal<=9999">已选商品({{skuTotal}})</el-button>
        <el-button type="primary" plain size="mini" v-else>已选商品(9999+)</el-button>
        <div>
          <el-button type="primary" @click="saveAllGoods">添加全部商品</el-button>
          <el-button type="primary" @click="add">添加商品</el-button>
          <el-button type="primary" @click="batchDeleteProduct">批量删除</el-button>
        </div>
      </div>
      <div>
        <el-table
          :data="productTableData"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          border
          default-expand-all
          row-key="goodsId"
          :size="size"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @selection-change="selectPorduct"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="goodsId" label="商品ID" sortable align="center"></el-table-column>
          <el-table-column prop="goodsName" label="商品名称" align="center"></el-table-column>
          <!-- <el-table-column prop="measureUnit" label="计量单位" align="center"></el-table-column> -->
          <el-table-column prop="goodsTypeName" label="商品类目" align="center"></el-table-column>
          <el-table-column prop="goodsPrice" label="价格（元）" align="center"></el-table-column>
          <el-table-column prop="reserveNum" label="库存" align="center"></el-table-column>
          <el-table-column label="店铺单渠道限购" align="center">
            <template slot-scope="scope">
              <el-input
                type="text"
                v-model.number="scope.row.storeChannelLimit"
                @blur="updateSkillPrice(scope.row)"
                style="width:120px;"
                :size="size"
                clearable
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="个人单渠道限购" align="center">
            <template slot-scope="scope">
              <el-input
                type="text"
                v-model.number="scope.row.userChannelLimit"
                @blur="updateSkillPrice(scope.row)"
                style="width:120px;"
                :size="size"
                clearable
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" fixed="right" align="center">
            <template slot-scope="scope">
              <el-button
                :size="size"
                type="text"
                @click="deleteProduct(scope.$index, scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="productTableData.length > 0" class="t_r">
        <el-pagination
          @size-change="goodsSizeChange"
          @current-change="goodsCurrentChange"
          :current-page="goodsStaticDataForm.start"
          :page-sizes="[10]"
          :page-size="goodsStaticDataForm.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="goodsTotal"
        ></el-pagination>
      </div>
    </div>

    <div v-if="active == 4" class="tab-container createSet tab-success">
      <div class="titleInfo">
        <img src="/static/images/success.png" />
        <span class="font20">创建成功!</span>
      </div>
      <div class="step-button2">
        <el-button type="primary" plain @click="viewList">查看活动列表</el-button>
        <template v-if="shenhe != 2">
          <kt-button
            type="primary"
             
            :size="size"
            @click="shenheHuodong(0)"
            perms="market:fullnum:submit"
            v-show="shenhe == 0"
            v-if="dataForm.status == 9 || dataForm.status == null"
            label="提交审核"
          />
        </template>
        <kt-button
          type="primary"
           
          :size="size"
          @click="shenheHuodong(1)"
          v-show="shenhe == 1"
          v-if="dataForm.status == 2"
          perms="market:fullnum:verify"
          label="审核"
        />
        <kt-button
          type="primary"
           
          :size="size"
          @click="templateDialogFormVisible = true"
          perms="market:fullnum:addtemp"
          label="保存模板"
        />
      </div>
    </div>

    <div class="step-button" v-if="active < 4">
      <el-button
        type="primary"
        :plain="active != 0 && active != 4"
        :size="size"
        v-if="active != 0 && active != 4"
        @click="back"
      >上一步</el-button>
      <el-button type="primary" v-if="active != 4" :size="size" @click="next">下一步</el-button>
    </div>
    <!-- 模板弹窗 -->
    <el-dialog title="保存模板" class="el-dialog-style" :visible.sync="templateDialogFormVisible">
      <el-form :model="templateForm" label-width="130px">
        <el-form-item label="模板名称：">
          <el-input v-model="templateForm.templateName" autocomplete="off" size="mini" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="templateDialogFormVisible=false" size="mini">取消</el-button>
        <el-button type="primary" @click="saveTemplate()" size="mini">保存模板</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt />
    </el-dialog>

    <el-dialog :visible.sync="dialogVisibleMerchant" title="添加商家">
      <el-form
        :inline="true"
        class="mb20"
        size="small"
        v-model="merchantDataForm"
        ref="merchantDataForm"
      >
        <el-row>
          <el-form-item label="商家名称：" prop="name">
            <el-input v-model="merchantDataForm.name" placeholder="商品名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="商家编码：" prop="orgNumber">
            <el-input v-model="merchantDataForm.orgNumber" placeholder="商品编码" clearable></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="queryPageMerchantManagement">搜索</el-button>
            <el-button type="primary" plain @click="restMerchantForm()">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div class="table-section">
        <el-table
          :data="merchantTableData"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          border
          :size="size"
          @selection-change="addMerchantChangeSelect"
        >
          <!-- <el-table-column prop="pictureUrl" label="主图" showImg="true"  align="center">
							<template slot-scope="scope">
							  　<img :src="scope.row.pictureUrl" width="30" height="30"/>
							</template>
          </el-table-column>-->
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="orgNumber" label="商家编码" sortable align="center"></el-table-column>
          <el-table-column prop="name" label="商家名称" align="center"></el-table-column>
          <el-table-column prop="merchantType" label="组织分类" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.merchantType == '1'">自营商家</span>
              <span v-else-if="scope.row.merchantType == '2'">第三方商家</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="chosenSelect">
        <span>已选择商家:{{addMerchantSelect.length}}</span>
        <div v-if="merchantTableData.length > 0" class="t_r">
          <el-pagination
            @size-change="merchanthandleSizeChange"
            @current-change="merchanthandleCurrentChange"
            :current-page="merchantDataForm.start"
            :page-sizes="[10]"
            :page-size="merchantDataForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="merchantListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="dialogVisibleMerchant=false" size="mini">取消</el-button>
        <el-button type="primary" @click="addMerchantChange" size="mini">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisibleStore" title="添加店铺">
      <el-form :inline="true" class="mb20" size="small" v-model="storeDataForm">
        <el-row>
          <el-form-item label="店铺名称：">
            <el-input v-model="storeDataForm.storeName" placeholder="店铺名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="店铺编码：">
            <el-input v-model="storeDataForm.storeCode" placeholder="店铺编码" clearable></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="queryPageStoreList">搜索</el-button>
            <el-button type="primary" plain @click="restStoreForm('storeDataForm')">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div class="table-section">
        <el-table
          :data="storeAddTableData"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          border
          :size="size"
          @selection-change="addStoreChangeSelect"
        >
          <!-- <el-table-column prop="pictureUrl" label="主图" showImg="true"  align="center">
							<template slot-scope="scope">
							  　<img :src="scope.row.pictureUrl" width="30" height="30"/>
							</template>
          </el-table-column>-->
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="storeCode" label="店铺编码" sortable align="center"></el-table-column>
          <el-table-column prop="storeName" label="店铺名称" align="center"></el-table-column>
        </el-table>
      </div>
      <div class="chosenSelect">
        <span>已选择店铺：{{addStoreSelect.length}}</span>
        <div v-if="storeAddTableData.length > 0" class="t_r">
          <el-pagination
            @size-change="storehandleSizeChange"
            @current-change="storehandleCurrentChange"
            :current-page="storeDataForm.start"
            :page-sizes="[10]"
            :page-size="storeDataForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="storeListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="dialogVisibleStore=false" size="mini">取消</el-button>
        <el-button type="primary" @click="addStoreChange" size="mini">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisibleTwo" title="添加商品">
      <el-form :inline="true" class="mb20" size="small" v-model="formInline">
        <el-row>
          <el-form-item label="商品名称：">
            <el-input v-model="formInline.goodsName" placeholder="商品名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="商品类目：">
            <el-input v-model="formInline.goodsCategory" placeholder="商品类目" clearable></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="queryPageProductManagement">搜索</el-button>
            <el-button type="primary" plain @click="restForm">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div class="table-section">
        <el-table
          :data="tableDataTwo"
          v-loading="productListloading"
          :header-cell-style="tableHeaderColor"
          ref="multipleTable"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          border
          :size="size"
          @selection-change="selectAddProductChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="thirdSpuId" label="商品编码" sortable align="center"></el-table-column>
          <el-table-column prop="goodsName" label="商品名称" align="center"></el-table-column>
          <el-table-column prop="measureUnit" label="计量单位" align="center"></el-table-column>
          <el-table-column prop="goodsCategory" label="商品类目" align="center"></el-table-column>
          <el-table-column prop="salePriceScope" label="价格（元）" align="center"></el-table-column>
          <el-table-column prop="stock" label="库存" align="center"></el-table-column>
        </el-table>
      </div>

      <div class="chosenSelect">
        <span>已选择商品：{{selectAddProduct.length}}</span>
        <div v-if="tableDataTwo.length > 0" class="t_r">
          <el-pagination
            @size-change="producthandleSizeChange"
            @current-change="producthandleCurrentChange"
            :current-page="formInline.start"
            :page-sizes="[10]"
            :page-size="formInline.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="productListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="dialogVisibleTwo=false" size="mini">取消</el-button>
        <el-button type="primary" @click="addProductChange" size="mini">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="审核" :visible.sync="dialogFormVisible" class="el-dialog-style">
      <el-form :model="form">
        <el-form-item class="textarea">
          <el-input v-model="form.checkRemark" autocomplete="off" type="textarea" rows="6" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="reviewDialog(4)" size="mini">审核拒绝</el-button>
        <el-button type="primary" @click="reviewDialog(9)" size="mini">审核通过</el-button>
      </div>
    </el-dialog>

    <el-dialog title="添加标签" :visible.sync="addTagDialogFormVisible" class="el-dialog-style">
      <el-form :model="addTagForm" :rules="addTagRules" ref="addTagForm">
        <el-form-item label="标签分类：" label-width="130px" prop="categoryId">
          <el-select v-model="addTagForm.categoryId" placeholder="请选择分类标签" size="mini" class="mb30">
            <el-option
              v-for="(item, index) in tagCategoryList"
              :key="index"
              :label="item.categoryName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称：" label-width="130px" prop="tagName">
          <el-input placeholder="请输入标签名称" v-model.trim="addTagForm.tagName" size="mini" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="addTagDialogFormVisible=false" size="mini">取消</el-button>
        <el-button type="primary" @click="addNewTag" size="mini">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { formatDate } from "@/utils/datetime";
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import KtButton from "@/views/Core/KtButton";

export default {
  components: {
    quillEditor,
    KtButton
  },
  data() {
    let this_ = this;

    // var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ]");
    var checkPromName = (rule, value, callback) => {
      //   debugger
      if (!value) {
        return callback(new Error("请输入活动名称"));
      } else if (value.length < 3 || value.length > 60) {
        return callback(new Error("名称长度在 3 到 60 个字符"));
      } else {
        callback();
      }
    };
    var checkSeckillTime = (rule, value, callback) => {
      //   debugger
      if (!value || !value[0]) {
        return callback(new Error("请选择活动开始时间"));
      } else if (!value[1]) {
        return callback(new Error("请选择活动结束时间"));
      } else if (value[0] >= value[1]) {
        return callback(new Error("活动开始时间不能大于结束时间"));
      } else {
        callback();
      }
    };
    var checkParentAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入母平台分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("母平台分摊比例格式错误"));
      } else {
        callback();
      }
    };
    var checkChildAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入子平台分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("子平台分摊比例格式错误"));
      } else {
        callback();
      }
    };
    var checkMerchantAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入商家分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("商家分摊比例格式错误"));
      } else {
        callback();
      }
    };
    var checkStoreAllocationScale = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入店铺分摊比例"));
      } else if (!/^[1-9][0-9]*([.][0-9]{1,2})?$/.test(value)) {
        //分摊比例为整数或两位小数
        callback(new Error("店铺分摊比例格式错误"));
      } else {
        callback();
      }
    };
    return {
      // 活动时间校验
      timeCheck: {
        disabledDate: time => {
          if (this.promotionStartEndTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() > new Date(this.promotionStartEndTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        }
      },
      templateDialogFormVisible: false, //模板弹窗
      templateForm: {}, //模板model
      formLabelWidth: "120px",
      dialogFormVisible: false,
      form: {},
      row: {},
      couponId: 0,
      activeName: "1",
      shenhe: 0,
      options: [
        {
          label: "食品",
          children: [
            {
              label: "乳制品",
              children: [
                {
                  label: "乳制品-外国"
                }
              ]
            }
          ]
        }
      ],
      productListloading: true,
      selectedOptions: [],
      formInline: {
        start: 1,
        limit: 10
      },
      tabsIndex: "first",
      tableData: [],
      tableDataTwo: [],
      dialogImageUrl: "",
      dialogVisible: false,
      dialogVisibleTwo: false,
      size: "mini",
      active: 0,
      dataForm: {
        grantType: "0",
        useChannel: [],
        使用时间设置: "1",
        startTime: new Date(),
        endTime: new Date(),
        TimeEveryDay: [],
        costAllocationFlag: "1", //是否分摊
        parcelsFlag: "0", //是否包邮
        overLimitRule: "1", //超限规则
        fileList: [], //图片List,
        storeCode: "0", //店铺地址
        merchantCode: "0", //商家地址
        proUserType: "0", //新老用户
        promType: "2",
        frontPromType: "2001",
        reduceFreight: "1",
        overlayAppNum: "0",
        fullNumCouponInfoList: [{ level: 1 }]
      },
      addDis: false, //是否隐藏新增阶梯
      addTimeEveryDayBtnStatus: false,
      labelPosition: "right",
      tagsList: [],
      addTagDialogFormVisible: false,
      addTagForm: {},
      addTagRules: {
        categoryId: [
          { required: true, message: "请选择标签分类", trigger: "change" }
        ],
        tagName: [
          { required: true, message: "请输入标签名称", trigger: "blur" }
        ]
      },
      tagCategoryList: [],
      //选择上传方式
      uploadMethodVisible: false,
      showFileList: false, //是否显示文件列表
      imgUrlList: [], //图片上传
      autoUpload: true, //图片自动上传
      materialLibraryVisible: false, //素材库弹窗
      materialImgNumber: 0, //选择素材数
      localTreeList: [], //本地树
      deptTreeList: [], //平台树
      defaultProps: {
        children: "treeInfoList",
        label: "categoryName"
      },
      //treeActiveName
      treeActiveName: "1",
      //查询素材列表分页
      materialQueryPageFilters: {
        start: 1,
        limit: 10,
        materialName: null
      },
      //素材分类tabs选项卡是否自动撑开
      stretch: true,
      //素材列表页title
      materialTitle: "",
      //素材List
      materialList: [],
      materialListTotal: 0, //素材列表总条数
      channelList: [], //渠道Tree List
      channlProps: {
        label: "childName"
      },
      //多选商家
      multipleMerchantSelection: [],
      //商家弹窗Form
      merchantTableData: [],
      merchantDataForm: {
        start: 1,
        limit: 10
      }, //商家搜索条件
      dialogVisibleMerchant: false, //商家弹窗
      //商家列表分页
      merchantListTotal: 0,
      multipleStoreSelection: [], //静态店铺多选
      addMerchantSelect: [], //新增商家选择
      storeTableData: [], //店铺列表静态
      dialogVisibleStore: false, //新增店铺窗口

      storeDataForm: {
        start: 1,
        limit: 10
      },
      storeAddTableData: [],
      addStoreSelect: [],
      storeListTotal: 0,

      //选择商品
      proActiveName: "1",
      activeProductName: "1",
      productTableData: [], //商品列表 静态表格
      selectAddProduct: [], //弹窗选择商品
      productListTotal: 0, //弹窗列表total
      productSelectFlag: [], //选择商品
      productActive: "",
      periodList: [],
      //时间段id
      timeOfDateId: "",
      skillId:
        this.$route.query.promotionId == null
          ? "0"
          : this.$route.query.promotionId, //秒杀id
      dataFormRules: {
        promName: [
          { required: true, validator: checkPromName, trigger: "blur" }
        ],
        SeckillTime: [
          { required: true, validator: checkSeckillTime, trigger: "blur" }
        ],
        startTimeEveryDay: [
          { required: true, message: "请选择时间段", trigger: "blur" }
        ],
        parentAllocationScale: [
          {
            required: true,
            validator: checkParentAllocationScale,
            trigger: "blur"
          },
          {
            required: true,
            validator: checkParentAllocationScale,
            trigger: "change"
          }
        ],
        childAllocationScale: [
          {
            required: true,
            validator: checkChildAllocationScale,
            trigger: "blur"
          },
          {
            required: true,
            validator: checkChildAllocationScale,
            trigger: "change"
          }
        ],
        merchantAllocationScale: [
          {
            required: true,
            validator: checkMerchantAllocationScale,
            trigger: "blur"
          },
          {
            required: true,
            validator: checkMerchantAllocationScale,
            trigger: "change"
          }
        ],
        storeAllocationScale: [
          {
            required: true,
            validator: checkStoreAllocationScale,
            trigger: "blur"
          },
          {
            required: true,
            validator: checkStoreAllocationScale,
            trigger: "change"
          }
        ],
        proUserType: [
          { required: true, message: "请选择用户类型", trigger: "change" }
        ],
        storeCode: [
          { required: true, message: "请选择店铺地址", trigger: "change" }
        ],
        merchantCode: [
          { required: true, message: "请选择商家地址", trigger: "change" }
        ],
        overlayAppNum: [
          { required: true, message: "请选择是否叠加", trigger: "change" }
        ],
        frontPromType: [
          { required: true, message: "请选择促销类型", trigger: "change" }
        ]
      },

      editorOption: {
        modules: {
          toolbar: [
            ["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
            ["blockquote", "code-block"], //引用，代码块
            [{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
            [{ list: "ordered" }, { list: "bullet" }], //列表
            [{ script: "sub" }, { script: "super" }], // 上下标
            [{ indent: "-1" }, { indent: "+1" }], // 缩进
            [{ direction: "rtl" }], // 文本方向
            [{ size: ["small", false, "large", "huge"] }], // 字体大小
            [{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题
            [{ color: [] }, { background: [] }], // 字体颜色，字体背景颜色
            [{ font: [] }], //字体
            [{ align: [] }], //对齐方式
            ["clean"], //清除字体样式
            ["image"] //上传图片、上传视频
          ]
        },
        theme: "snow"
      }, //富文本编辑器
      descriptions: "满量减", //描述
      deptType: localStorage.getItem("deptType"), //当前登录用户所属组织类型
      //商家页分页
      merchantStaticDataForm: {
        start: 1,
        limit: 10
      },
      merchantTotal: 0,

      //商家页分页
      storeStaticDataForm: {
        start: 1,
        limit: 10
      },
      storeTotal: 0,
      //商品也分页查询
      goodsTotal: 0,
      goodsStaticDataForm: {
        start: 1,
        limit: 10
      },
      skuTotal: 0 //已选择Sku数量
    };
  },
  methods: {
    /**
     * 清空店铺输入框
     */
    restStoreForm() {
      this.$set(this.storeDataForm, "storeCode", null);
      this.$set(this.storeDataForm, "storeName", null);
      this.$set(this.storeDataForm, "start", 1);
      this.queryPageStoreList();
    },
    /**
     * channelIdsChange
     */
    channelIdsChange(val, checkedKeys) {
      this.$set(this.dataForm, "channelIds", checkedKeys.checkedKeys);
    },
    /**
     * 是否分摊校验
     */
    costAllocationFlagChanage(val) {
      if (val == 2) {
        this.dataFormRules.costAllocationFlag[0].required = false;
      } else {
        this.dataFormRules.costAllocationFlag[0].required = true;
      }
    },
    /**
     * 添加全部商品
     */
    saveAllGoods() {
      this.utils.request.fullNumAddAllGoods(
        { promotionId: this.skillId },
        res => {
          this.goodsCurrentChange(1);
        }
      );
    },
    /**
     * 商品页分页
     */
    goodsSizeChange() {},
    goodsCurrentChange(val) {
      this.goodsStaticDataForm.start = val;
      this.skillQueryGoods();
    },
    /**
     * 商家页分页
     */
    merchantSizeChange() {},
    merchantCurrentChange(val) {
      this.merchantStaticDataForm.start = val;
      this.skillQueryMerchant();
    },
    /**
     * 店铺
     */
    storeSizeChange() {},
    storeCurrentChange(val) {
      this.storeStaticDataForm.start = val;
      this.skillQueryStore();
    },
    /**
     * 清空商家搜索框
     */
    restMerchantForm() {
      this.$set(this.merchantDataForm, "orgNumber", "");
      this.$set(this.merchantDataForm, "name", "");
      this.$set(this.merchantDataForm, "start", 1);
      this.queryPageMerchantList();
    },
    /**
     * 弹窗条件查询商家
     */
    queryPageMerchantManagement() {
      this.merchantDataForm.start = 1;
      this.queryPageMerchantList();
    },
    /**
     * 保存模板
     */
    saveTemplate() {
      var that = this;
      this.templateForm.promotionId = this.skillId;
      if (
        this.templateForm.templateName == null ||
        this.templateForm.templateName == ""
      ) {
        that.$message({ message: "模板名称不能为空", type: "error" });
        return false;
      }
      const loading = this.$loading({
        lock: true,
        text: "小的正在加载中,请稍后...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.utils.request.fullNumSaveTemplate(this.templateForm, res => {
        loading.close();
        if (res.code == "0000") {
          this.$message({ message: "保存成功", type: "success" });
          this.templateDialogFormVisible = false;
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },
    /**
     * 查看示例
     */
    example() {},
    /**
     * 删除阶梯
     */
    removePromotionRuleSet(index, row) {
      this.dataForm.fullNumCouponInfoList.splice(index, 1);
    },
    /**
     * 新增阶梯
     */
    addPromotionRuleSet() {
      let level = 1;
      if (this.dataForm.fullNumCouponInfoList.length > 0) {
        level =
          this.dataForm.fullNumCouponInfoList[
            this.dataForm.fullNumCouponInfoList.length - 1
          ].level + 1;
      }
      this.dataForm.fullNumCouponInfoList.push({ level: level });
    },
    /**
     * 修改商品价格
     */
    updateSkillPrice(row) {

      if(!this.checkProductLimits(row)){
        return false;
      }

      let param = {
        goodsInfoList: [row],
        promotionId: this.skillId
      };
      this.utils.request.fullNumUpdateGoods(param, res => {});
    },
    /**
     * 子母平台分摊监听
     */
    keyupCost(val, flag) {
      let checkNumber = /^\d{3}$/;
    },
    /**
     * 查询标签List
     */
    queryTagList(id) {
      let that = this;
      this.utils.request.getTagList({}, res => {
        this.tagsList = res.data.rows;
        if (id != null) {
          this.dataForm.label = id;
        }
        //编辑回显
        if (this.skillId != "0") {
          this.utils.request.fullNumQueryConfig(
            { promotionId: this.skillId },
            data => {
              for (const key in data.data) {
                this.$set(that.dataForm, key, data.data[key]);
              }
              this.$set(that.dataForm, "status", data.data["status"]);
              //回显使用渠道
              if (
                that.deptType == 0 &&
                data.data.channelCodes != null &&
                data.data.channelCodes.length > 0
              ) {
                this.$set(
                  that.dataForm,
                  "channelCodes",
                  data.data["channelCodes"]
                );
                this.$set(
                  that.dataForm,
                  "channelIds",
                  res.data["channelCodes"]
                );
                that.$refs.channelTree.setCheckedKeys(data.data.channelCodes);
              }
              this.$set(that.dataForm, "SeckillTime", [
                new Date(data.data["startTime"]),
                new Date(data.data["endTime"])
              ]);
              this.$set(that.dataForm, "label", Number(data.data["label"]));
              if (data.data["frontPromType"] == "2003") {
                if (
                  data.data["fullNumCouponInfoList"] != null &&
                  data.data["fullNumCouponInfoList"][0].goodsPrice == "-1"
                ) {
                  this.$set(
                    that.dataForm,
                    "numberOfPieces",
                    data.data["fullNumCouponInfoList"][0]["goodsNum"]
                  );
                  this.$set(
                    that.dataForm.fullNumCouponInfoList[0],
                    "goodsPrice",
                    "-1"
                  );
                  this.$set(that.dataForm, "reduceFreight", "1");
                } else if (
                  data.data["fullNumCouponInfoList"] != null &&
                  data.data["fullNumCouponInfoList"][0].goodsPrice != "-1"
                ) {
                  this.$set(
                    that.dataForm,
                    "numberOfPiecesTwo",
                    data.data["fullNumCouponInfoList"][0]["goodsNum"]
                  );
                  this.$set(
                    that.dataForm,
                    "freight",
                    data.data["fullNumCouponInfoList"][0].goodsPrice
                  );
                  this.$set(that.dataForm, "reduceFreight", "2");
                }
              } else {
                //阶梯回显
                let level = 1;
                data.data["fullNumCouponInfoList"].forEach(item => {
                  item["level"] = level;
                  level++;
                });
                this.$set(
                  this.dataForm,
                  "fullNumCouponInfoList",
                  data.data["fullNumCouponInfoList"]
                );
              }
            }
          );
        }
      });
    },
    /**
     * 标签分类查询
     */
    getTagCategoryList() {
      let that = this;
      this.utils.request.getTagCategoryList({}, res => {
        this.tagCategoryList = res.data.rows;
      });
    },
    /**
     * 查询关联
     */
    skillQueryMerchant() {
      let that = this;
      this.merchantStaticDataForm.promotionId = this.skillId;
      this.utils.request.fullNumQueryMerchant(
        this.merchantStaticDataForm,
        res => {
          if (res != null && res.data != null) {
            this.tableData =
              res.data.merchantInfoList == null
                ? []
                : res.data.merchantInfoList;
            let data = [];
            this.tableData.forEach(item => {
              data.push({
                orgNumber: item.orgNumber,
                id: item.merchantId,
                name: item.merchantName,
                merchantType: item.merchantTypeId
              });
            });
            this.tableData = data;
            this.merchantTotal = Number(res.data.total);
          }
        }
      );
    },
    /**
     * 查询关联的店铺
     */
    skillQueryStore() {
      let that = this;
      this.storeStaticDataForm.promotionId = this.skillId;
      this.utils.request.fullNumQueryStore(this.storeStaticDataForm, res => {
        if (res != null && res.data != null) {
          this.storeTableData =
            res.data.storeInfoList == null ? [] : res.data.storeInfoList;
          let data = [];
          this.storeTableData.forEach(item => {
            data.push({
              id: item.storeId,
              storeName: item.storeName,
              storeCode: item.storeCode,
              merchantId: item.merchantId
            });
          });
          this.storeTableData = data;
          this.storeTotal = Number(res.data.total);
        }
      });
    },
    skillQueryGoods() {
      let that = this;
      this.goodsStaticDataForm.promotionId = this.skillId;
      that.utils.request.fullNumQueryGoods(this.goodsStaticDataForm, data => {
        if (data != null) {
          that.productTableData = data.data.fullNumGoodsInfos;
          that.goodsTotal = Number(data.data.total);
          that.skuTotal = Number(data.data.skuTotal);
        }
      });
    },
    /**
     * 保存店铺商家
     */
    relatedMerchant() {
      this.active++;
      //保存完商家、店铺后清空本地商品信息，防止接口返回慢还展示商品信息
      this.productTableData = [];
      this.skillQueryGoods();
    },
    /**
     * 确认添加商品
     */
    addProductChange(val) {
      if (this.selectAddProduct.length < 1) {
        this.$message({ message: "请选择要添加的商品", type: "warning" });
        return false;
      }
      this.productTableData.forEach(res => {
        this.selectAddProduct.forEach((item, index) => {
          //排除已保存过的商品
          if (res.goodsId == item.id) {
            this.selectAddProduct.splice(index, 1);
          }
        });
      });
      if (this.selectAddProduct && this.selectAddProduct.length > 0) {
        this.productTableData = this.productTableData.concat(
          this.selectAddProduct
        );
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
        this.relatedProducts();
      } else {
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
      }
    },
    selectPorduct(val) {
      this.productSelectFlag = val;
    },
    /**
     * 条数刷新
     */
    producthandleSizeChange(val) {},
    /**
     * 换页刷新
     */
    producthandleCurrentChange(val) {
      this.formInline.start = val;
      this.queryPageProductManagement();
    },
    /**
     * 选择商品
     */
    selectAddProductChange(val) {
      this.selectAddProduct = val;
    },
    /**
     * 批量删除商品
     */
    batchDeleteProduct() {
      if (this.productSelectFlag.length < 1) {
        this.$message({ message: "请选择要删除的商品", type: "warning" });
        return false;
      }
      this.$confirm("确定删除吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          this.productSelectFlag.forEach(item => {
            this.utils.request.fullNumDeleteGoods(
              { goodsId: item.goodsId, promotionId: this.skillId },
              res => {
                this.skillQueryGoods();
              }
            );
          });
          this.productSelectFlag = [];
        })
        .catch(() => {});
    },
    deleteProduct(index, row) {
      let proId = row.goodsId;
      this.utils.request.fullNumDeleteGoods(
        { goodsId: row.goodsId, promotionId: this.skillId },
        res => {
          this.skillQueryGoods();
        }
      );
    },
    /**
     * 弹窗选择店铺
     */
    addStoreChangeSelect(val) {
      this.addStoreSelect = val;
    },
    /**
     * 弹窗换页刷新
     */
    storehandleSizeChange(val) {
      this.storeDataForm.limit = val;
      this.queryPageStoreList();
    },
    /**
     * 弹窗翻页
     */
    storehandleCurrentChange(val) {
      this.storeDataForm.start = val;
      this.queryPageStoreList();
    },
    /**
     * 确认添加店铺
     */
    addStoreChange() {
      if (this.addStoreSelect.length < 1) {
        this.$message({ message: "请选择要添加的店铺", type: "warning" });
        return false;
      }
      this.storeTableData.forEach(res => {
        this.addStoreSelect.forEach((item, index) => {
          //排除已保存过的店铺
          if (res.id == item.id) {
            this.addStoreSelect.splice(index, 1);
          }
        });
      });
      if (this.addStoreSelect && this.addStoreSelect.length > 0) {
        let that = this;
        let paramData = [];
        this.addStoreSelect.forEach(item => {
          paramData.push({
            merchantId: item.merchantId,
            storeName: item.storeName,
            storeId: item.id,
            storeCode: item.storeCode,
            // "storeId":item.id,
            channelCode: ""
          });
        });
        let param = { promotionId: this.skillId, storeInfoList: paramData };
        this.utils.request.fullNumAddStore(param, res => {
          this.dialogVisibleStore = !this.dialogVisibleStore;
          this.addStoreSelect = [];
          this.skillQueryStore();
        });
      } else {
        this.dialogVisibleStore = !this.dialogVisibleStore;
      }
    },
    /**
       添加店铺
       */
    addStore() {
      // debugger;
      if (this.tableData.length == 0) {
        this.$message({ message: "请先选择店铺", type: "warning" });
        return false;
      }
      this.queryPageStoreList();
      this.dialogVisibleStore = true;
    },
    /**
     * 批量删除店铺
     */
    batchDeleteStore() {
      if (this.multipleStoreSelection.length < 1) {
        this.$message({ message: "请选择要删除的店铺", type: "warning" });
        return false;
      }
      this.$confirm("确定删除吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          this.multipleStoreSelection.forEach(item => {
            for (let index = 0; index < this.storeTableData.length; index++) {
              if (this.storeTableData[index].id == item.id) {
                this.storeTableData.splice(index, 1);
              }
            }
            this.utils.request.fullNumDeleteStore(
              { promotionId: this.skillId, storeId: item.id },
              res => {}
            );
          });
          this.multipleStoreSelection = [];
        })
        .catch(() => {});
    },
    /**
     * 选择店铺
     */
    selectStoreChange(val) {
      this.multipleStoreSelection = val;
    },
    /**
     * 删除店铺
     */
    handleDeleteStore(index, row) {
      let proId = row.id;
      for (var i = 0; i < this.storeTableData.length; i++) {
        if (this.storeTableData[i].id == proId) {
          this.storeTableData.splice(i, 1);
        }
      }
      this.utils.request.fullNumDeleteStore(
        { promotionId: this.skillId, storeId: proId },
        res => {}
      );
    },

    /**
     * 新增商家选择
     */
    addMerchantChangeSelect(val) {
      this.addMerchantSelect = val;
    },
    /**
     * 添加商家
     */
    addMerchantChange() {
      if (this.addMerchantSelect.length < 1) {
        this.$message({ message: "请选择要添加的商家", type: "warning" });
        return false;
      }
      this.tableData.forEach(res => {
        this.addMerchantSelect.forEach((item, index) => {
          //排除已保存过的商家
          if (res.id == item.id) {
            this.addMerchantSelect.splice(index, 1);
          }
        });
      });
      if (this.addMerchantSelect && this.addMerchantSelect.length > 0) {
        this.tableData = this.tableData.concat(this.addMerchantSelect);
        let that = this;
        let paramData = [];
        this.addMerchantSelect.forEach(item => {
          paramData.push({
            merchantId: item.id,
            orgNumber: item.orgNumber,
            merchantName: item.name,
            merchantTypeId: item.merchantType,
            merchantTypeName:
              item.merchantType == "1" ? "自营商家" : "第三方商家",
            channelCode: ""
          });
        });
        let param = { promotionId: this.skillId, merchantInfoList: paramData };
        this.utils.request.fullNumAddMerchant(param, res => {
          this.dialogVisibleMerchant = !this.dialogVisibleMerchant;
          this.addMerchantSelect = [];
          this.skillQueryMerchant();
        });
      } else {
        this.dialogVisibleMerchant = !this.dialogVisibleMerchant;
      }
    },
    /**
     * 商家列表换页刷薰
     *
     */
    merchanthandleSizeChange(val) {
      this.merchantDataForm.limit = val;
      this.queryPageMerchantList();
    },
    merchanthandleCurrentChange(val) {
      this.merchantDataForm.start = val;
      this.queryPageMerchantList();
    },
    uploadMethod(val) {
      let param = new FormData();
      param.append("name", "wiiiiiinney");
      //通过append向form对象添加数据
      param.append("file", val.file);
      //FormData私有类对象，访问不到，可以通过get判断值是否传进去
      this.utils.request.upload(param);
    },
    /**
     * 批量删除商家
     */
    batchDeleteMerchant() {
      if (this.multipleMerchantSelection.length < 1) {
        this.$message({ message: "请选择要删除的商家", type: "warning" });
        return false;
      }
      this.$confirm("确定删除吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          this.multipleMerchantSelection.forEach(item => {
            for (let index = 0; index < this.tableData.length; index++) {
              if (this.tableData[index].id == item.id) {
                this.tableData.splice(index, 1);
              }
            }
            this.utils.request.fullNumDeleteMerchant(
              { merchantId: item.id, promotionId: this.skillId },
              res => {
                this.merchantStaticDataForm.start = 1;
                this.storeStaticDataForm.start = 1;
                this.skillQueryMerchant();
                this.skillQueryStore();
              }
            );
          });
          this.multipleMerchantSelection = [];
        })
        .catch(() => {});
    },
    /**
     * 多选商家
     */
    selectMerchantChange(val) {
      this.multipleMerchantSelection = val;
    },

    /**
     * delete图片列表
     */
    deleteimgUrlList(index) {
      this.imgUrlList.splice(index, 1);
    },
    /**
     * 素材列表条数
     */
    handleSizeChange(val) {
      this.materialQueryPageFilters.limit = val;
      this.handleNodeClick(undefined);
    },
    /**
     * 换页
     */
    handleCurrentChange(val) {
      this.materialQueryPageFilters.start = val;
      this.handleNodeClick(undefined);
    },
    /**
     *选择素材
     */
    selectMaterial(index) {
      if (this.materialList[index].isSelect == undefined) {
        this.materialList[index].isSelect = false;
      }
      if (this.materialList[index].isSelect) {
        this.materialImgNumber--;
      } else {
        this.materialImgNumber++;
      }
      this.materialList[index].isSelect = !this.materialList[index].isSelect;
    },
    /**
     * 素材确认
     */
    addMaterial() {
      let flag = true;
      this.materialList.forEach(item => {
        if (item.isSelect) {
          flag = false;
          this.imgUrlList.push({ url: item.materialUrl, hover: null });
        }
      });
      if (flag) {
        this.$message({ message: "请选择要选用素材", type: "warning" });
        return false;
      }
      this.materialLibraryVisible = false;
      this.uploadMethodVisible = false;
      this.$message({ message: "选用成功", type: "success" });
    },
    /**
     * 菜单树选项卡
     */
    handleNodeClick(data) {
      if (data != undefined && data.id != null) {
        this.materialQueryPageFilters.materialName = null;
      }
      this.materialTitle =
        data != undefined && data.categoryName != null
          ? data.categoryName
          : this.materialTitle;
      this.materialQueryPageFilters.categoryId =
        data != undefined && data.id != null
          ? data.id
          : this.materialQueryPageFilters.categoryId;
      this.materialQueryPageFilters.materialName =
        this.materialQueryPageFilters.materialName == ""
          ? null
          : this.materialQueryPageFilters.materialName;
      this.utils.request.materialQueryPage(
        this.materialQueryPageFilters,
        res => {
          res.data.rows.forEach(item => {
            item.isSelect = false;
          });
          this.materialList = res.data.rows;
          this.materialListTotal = res.data.total;
        }
      );
    },
    /**
     * 菜单树选项卡
     */
    handleClick(val) {},
    /**
     * 查询素材树
     */
    materialQueryTree() {
      let that = this;
      this.utils.request.materialQueryTree({}, res => {
        this.deptTreeList = res.data.deptTreeList;
        this.localTreeList = res.data.localTreeList;
      });
    },
    /**
     * 本地上传图片成功回调
     */
    imgUploadSuccess(response, file, fileList) {
      // debugger
      this.imgUrlList.push({ url: URL.createObjectURL(file.raw), hover: null });
      this.uploadMethodVisible = false;
    },
    imgUploadError(err, file, fileList) {
      this.$message({ message: "文件上传失败,请重新上传", type: "error" });
    },
    /**
     * 选择上传方式弹窗
     */
    selectUploadMethod() {
      this.uploadMethodVisible = true;
    },
    /**
     * 鼠标移入
     */
    mouseEnter(index) {
      // debugger
      this.imgUrlList[index].hover = true;
    },
    /**
     * 鼠标移出
     */
    mouseLeave(index) {
      // debugger
      this.imgUrlList[index].hover = null;
    },
    /**
     * 新增标签弹窗
     */
    addtags() {
      if (this.$refs["addTagForm"] != undefined) {
        this.$refs["addTagForm"].resetFields();
      }
      this.addTagDialogFormVisible = true;
    },
    /**
     * 新增标签
     */
    addNewTag() {
      this.$refs["addTagForm"].validate(valid => {
        if (valid) {
          //TODO 新增标签
          // this.addTagForm
          let that = this;
          this.utils.request.addTag(this.addTagForm, res => {
            that.queryTagList(res.data);
            that.addTagDialogFormVisible = false;
          });
        } else {
          return false;
        }
      });
    },
    /**
     * 新增时间段
     */
    addTimeEveryDay() {
      // debugger
      if (!this.dataForm.startTimeEveryDay || !this.dataForm.endTimeEveryDay) {
        this.$message({
          message: "请填写完整最后一个时段后再新增时段",
          type: "error"
        });
        return false;
      }
      let flag = false;
      if (this.dataForm.TimeEveryDay.length > 0) {
        this.dataForm.TimeEveryDay.forEach(function(item, index) {
          if (
            item.startTimeEveryDay == undefined ||
            item.endTimeEveryDay == undefined
          ) {
            flag = true;
            return;
          }
        });
      }
      if (flag) {
        this.$message({
          message: "请填写完整最后一个时段后再新增时段",
          type: "error"
        });
        return false;
      }
      this.dataForm.TimeEveryDay.push({});
      if (this.dataForm.TimeEveryDay.length >= 11) {
        this.addTimeEveryDayBtnStatus = true;
        return false;
      }
    },
    /**
     * 删除时间段
     */
    deleteTimeEveryDay(index) {
      this.$confirm(
        "此操作会将该时间段内的选品一并删除，确定要删除该时间段吗？",
        "提示",
        {
          type: "warning"
        }
      )
        .then(() => {
          this.dataForm.TimeEveryDay.splice(index, 1);
        })
        .catch(() => {});
    },
    /**
     * 格式化时间段
     */
    formatTimeEveryDay(date) {
      if (date == undefined) {
        return "";
      }
      // debugger
      let dataList = date.split(":");
      let time = Number(dataList[0]) - 1 + "";
      let returnTime;
      if (time.length < 2) {
        returnTime = "0" + time + ":" + dataList[1];
      } else {
        returnTime = time + ":" + dataList[1];
      }
      return returnTime;
    },
    /**
     * 格式化活动时间
     */
    SeckillTimeChanage(e) {
      let startTime = formatDate(e[0], "yyyy-MM-dd hh:mm:ss");
      let startTimeArray = startTime.split(" ");
      if (startTimeArray[1] == "00:00:00") {
        // debugger
        startTime =
          startTimeArray[0] +
          " " +
          formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").split(" ")[1];
      }
      let endTime = formatDate(e[1], "yyyy-MM-dd hh:mm:ss");
      let endTimeArray = endTime.split(" ");
      if (endTimeArray[1] == "00:00:00") {
        // debugger
        endTime =
          endTimeArray[0] +
          " " +
          formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").split(" ")[1];
      }
      // debugger
      this.dataForm.startTime = startTime;
      this.dataForm.endTime = endTime;
      let startYearDate = startTime.split("-");
      let startTimeDate = startTime.split(":");

      let endYearDate = endTime.split("-");
      let endTimeDate = endTime.split(":");
      // debugger
      this.dataForm.SeckillTime = [
        new Date(
          startYearDate[0],
          startYearDate[1],
          startYearDate[2].split(" ")[0],
          startTimeDate[0].split(" ")[1],
          startTimeDate[1],
          startTimeDate[2]
        ),
        new Date(
          endYearDate[0],
          endYearDate[1],
          endYearDate[2].split(" ")[0],
          endTimeDate[0].split(" ")[1],
          endTimeDate[1],
          endTimeDate[2]
        )
      ];
    },
    select(row) {
      let flag = true;
      this.tableData.forEach(res => {
        if (res.id == row.id) {
          this.$message({ message: "不能添加重复商品", type: "error" });
          flag = false;
        }
      });
      if (flag) {
        this.tableData.push(row);
        this.dialogVisibleTwo = !this.dialogVisibleTwo;
      }
    },
    handleChange(myArray) {},
    add() {
      this.queryPageProductManagement();
      this.dialogVisibleTwo = true;
    },
    /**
     * 添加商家按钮
     */
    addMerchant() {
      // this.queryPageProductManagement();
      this.queryPageMerchantList();
      this.dialogVisibleMerchant = true;
    },
    queryPageMerchantList() {
      let that = this;
      this.productListloading = true;
      //只有运营平台有使用渠道
      if (this.deptType == 0) {
        this.merchantDataForm.childIds = that.dataForm.channelIds;
      }
      this.utils.request.queryMerchantList(this.merchantDataForm, res => {
        that.productListloading = false;
        if (res.code == "0000") {
          that.merchantTableData = res.data.rows;
          that.merchantListTotal = res.data.total;
        }
      });
    },
    queryPageStoreList() {
      this.utils.request.couponGetMerchantIdsByPromotionId(
        { promotionId: this.skillId },
        data => {
          if (data.data.length == 0) {
            this.$message({ message: "请先选择商家", type: "success" });
            return false;
          }
          let this_ = this;
          this.productListloading = false;
          this.storeDataForm.merchantIds = data.data.join(",");
          this.utils.request.queryByIds(this.storeDataForm, function(res) {
            if (res.code == "0000") {
              this_.storeAddTableData = res.data.rows;
              this_.storeListTotal = res.total;
            }
          });
        }
      );
    },
    //table的双色条纹
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    //修改table header的背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color:rgb(250,250,250);";
      }
    },

    handleDelete(index, row) {
      let proId = row.id;
      for (var i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].id == proId) {
          this.tableData.splice(i, 1);
        }
      }
      //删除商家
      this.utils.request.fullNumDeleteMerchant(
        { merchantId: proId, promotionId: this.skillId },
        res => {
          this.merchantStaticDataForm.start = 1;
          this.storeStaticDataForm.start = 1;
          this.skillQueryMerchant();
          this.skillQueryStore();
        }
      );
    },
    next() {
      if (this.active == 0) {
        //提交订单
        this.submitCouponInfo("dataForm");
      } else if (this.active == 1) {
        //关联商家店铺
        //判断是否添加商家, 店铺
        if (this.tableData.length < 1) {
          this.$message({ message: "请选择商家", type: "error" });
          return false;
        } else if (this.storeTableData.length < 1) {
          this.$message({ message: "请选择店铺", type: "error" });
          return false;
        } else {
          this.relatedMerchant();
        }
      } else if (this.active == 2) {
        //关联商品

        let flag = true;
        this.productTableData.forEach(product=>{
          if(!this.checkProductLimitsIsNull(product)){
            flag = false;
          }
          product.children.forEach(childrenProduct=>{
            if(!this.checkProductLimitsIsNull(childrenProduct)){
              flag = false;
            }
          })
        })
        if(!flag){
          this.$message({ message: "请输入必填项", type: "error" });
          return false;
        }

        //修改状态
        let that = this;
        if (this.dataForm.status == 9 || this.dataForm.status == null) {
          this.utils.request.fullNumCheckFullnum(
            { promotionId: this.skillId, updateStatus: "1" },
            res => {
              that.active = that.active + 2;
            }
          );
        }
      } else {
        this.active = this.active + 1;
      }
    },
    back() {
      this.active = this.active - 1;
      //如果等于0 回显使用渠道
      if (this.active == 0) {
        if (this.deptType == 0) {
          this.$nextTick(() => {
            this.$refs.channelTree.setCheckedKeys(
              this.dataForm.channelCodes.split(",")
            );
          });
        }
      }
    },
    viewList() {
      this.$router.push({
        path: "/pages/promotionManagement/FullNumPromotion"
      });
    },
    shenheHuodong(flag) {
      if (flag == 0) {
        //提交审核
        let that = this;
        this.utils.request.fullNumCheckFullnum(
          { promotionId: this.skillId, updateStatus: 2 },
          res => {
            this.shenhe = 1;
            that.$message({ message: "提交审核成功", type: "success" });
          }
        );
      } else {
        //审核
        this.dialogFormVisible = true;
      }
      // this.$message({ message: "操作成功", type: "success" });
    },
    dateFilter: function(input) {
      var d = new Date(input);
      var year = d.getFullYear();
      var month =
        d.getMonth() < 9 ? "0" + (d.getMonth() + 1) : "" + (d.getMonth() + 1);
      var day = d.getDate() < 10 ? "0" + d.getDate() : "" + d.getDate();
      var hour = d.getHours() < 10 ? "0" + d.getHours() : "" + d.getHours();
      var minutes =
        d.getMinutes() < 10 ? "0" + d.getMinutes() : "" + d.getMinutes();
      var seconds =
        d.getSeconds() < 10 ? "0" + d.getSeconds() : "" + d.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    /* 提交优惠券信息 */
    submitCouponInfo(formName) {
      //  this.active = this.active + 1;
      this.$refs[formName].validate(valid => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "小的正在努力加载中......",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.8)"
          });

          //如分摊则校验分摊比例总和不能超过100
          if (this.dataForm.costAllocationFlag == "1") {
            if (
              Number(this.dataForm.parentAllocationScale) +
                Number(this.dataForm.childAllocationScale) +
                Number(this.dataForm.merchantAllocationScale) +
                Number(this.dataForm.storeAllocationScale) !=
              100
            ) {
              this.$message({ message: "分摊比例总和为100", type: "warning" });
              loading.close();
              return false;
            }
          }
          //当前登录用户身份为母平台校验所属渠道
          if (this.deptType == 0) {
            if (this.$refs.channelTree.getCheckedKeys().length <= 0) {
              this.$message({ message: "请选择使用渠道" });
              loading.close();
              return false;
            } else {
              this.dataForm.channelCodes = this.$refs.channelTree
                .getCheckedKeys()
                .join(",");
            }
          } else {
            //非母平台清除子平台编码
            if (this.dataForm.channelCodes) {
              delete this.dataForm.channelCodes;
            }
          }

          if (this.dataForm.frontPromType == "2003") {
            this.dataForm.fullNumCouponInfoList = [];
            this.dataForm.fullNumCouponInfoList.push({
              goodsNum:
                this.dataForm.reduceFreight == "1"
                  ? this.dataForm.numberOfPieces
                  : this.dataForm.numberOfPiecesTwo,
              goodsPrice:
                this.dataForm.reduceFreight == "1"
                  ? "-1"
                  : this.dataForm.freight
            });
          }
          // this.dataForm.timeInfoList = this.dataForm.timeInfoList.concat(this.dataForm.TimeEveryDay);
          let that = this;
          if (this.skillId != "0") {
            this.dataForm.promotionId = this.skillId;
            this.utils.request.fullNumUpdateConfig(this.dataForm, res => {
              loading.close();
              if (res.code == "0000") {
                that.merchantStaticDataForm.start = 1;
                that.skillQueryMerchant();
                that.skillQueryStore();
                that.active = that.active + 1;
              } else {
                that.$message({
                  message: res.msg || "更新满量失败,请重试",
                  type: "error"
                });
              }
            });
          } else {
            this.utils.request.fullNumAddConfig(this.dataForm, res => {
              loading.close();
              if (res.code == "0000") {
                that.skillId = res.data;
                that.merchantStaticDataForm.start = 1;
                that.skillQueryMerchant();
                that.skillQueryStore();
                that.active = that.active + 1;
              } else {
                that.$message({
                  message: res.msg || "新增满量失败,请重试",
                  type: "error"
                });
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    restForm() {
      this.formInline.goodsCategory = null;
      this.formInline.goodsName = null;
      this.queryPageProductManagement();
    },
    queryPageProductManagement() {
      let that = this;
      this.productListloading = true;
      this.formInline.goodsCategory =
        this.formInline.goodsCategory == ""
          ? null
          : this.formInline.goodsCategory;
      this.formInline.goodsName =
        this.formInline.goodsName == "" ? null : this.formInline.goodsName;
      this.utils.request.couponGetStoreIdsByPromotionId(
        { promotionId: this.skillId },
        data => {
          if (data.data == null && data.data.length < 1) {
            this.$message({ message: "请选择店铺", type: "error" });
            this.active = this.active - 1;
            return false;
          }
          this.formInline.storeIds = data.data;
          this.utils.request.marketQuerySPUList(
            this.formInline,
            res => {
              that.productListloading = false;
              if (res.code == "0000") {
                that.tableDataTwo = res.data.rows;
                that.productListTotal = res.data.total;
              }
            }
          );
        }
      );
    },
    /* 关联商品 */
    relatedProducts() {
      if (this.productTableData.length < 1) {
        this.$message({ message: "所关联的商品不能为空", type: "warning" });
        return false;
      }
      let that = this;
      let param = this.selectAddProduct.map(item => item.id);
      this.utils.request.fullNumAddGoods(
        { promotionId: this.skillId, goodsInfoList: param },
        res => {
          if (res != null && res.data != null && res.code == "0000") {
            //商品新增成功
            that.skillQueryGoods();
            that.selectAddProduct = [];
          }
        }
      );
    },
    reviewDialog: function(data) {
      let that = this;
      this.form.promotionId = this.skillId;
      this.form.updateStatus = data;
      if (
        data == 4 &&
        (this.form.checkRemark == null || this.form.checkRemark == "")
      ) {
        this.$message({ message: "审核拒绝必须输入拒绝理由", type: "error" });
        return false;
      }
      that.utils.request.fullNumCheckFullnum(this.form, res => {
        if (res.code == "0000") {
          that.dialogFormVisible = false;
          that.$message({ message: "审核完成", type: "success" });
          // that.findPage();
          that.shenhe = 2;
        } else {
          that.$message({ message: "审核失败", type: "error" });
        }
      });
    },
    changeDescriptions(val) {
      if (val == "2001") {
        this.descriptions = "满量减";
      } else if (val == "2002") {
        this.descriptions = "满量折";
      } else {
        this.descriptions = "满量减运费";
      }
    },
    //获取子平台列表
    getChildList() {
      let channel = { childName: "卡奥斯运营平台", id: "179" };
      let that = this;
      this.utils.request.queryChildList({}, res => {
        if (res.code == "0000" && res.data && res.data.length > 0) {
          channel.children = res.data;
          that.channelList.push(channel);

          that.defaultChecked(channel);
        }
      });
    },
    defaultChecked(channel) {
      //判断是否是修改 如果是修改 不默认选中全部
      if (this.skillId == null || this.skillId == "0") {
        let ids = this.channelList[0].children.map(item => item.id);
        ids.push(channel.id + "");
        this.$set(this.dataForm, "channelCodes", ids);
        this.$set(this.dataForm, "channelIds", ids);
        this.$nextTick(() => {
          this.$refs.channelTree.setCheckedKeys(ids);
        });
      }
    },

    checkProductLimitsIsNull(row){
      if(row.storeChannelLimit == null || row.storeChannelLimit == '' || row.userChannelLimit == null || row.userChannelLimit == '' ){
        return false;
      }
      return true;
    },


    //检验商品
     checkProductLimits(row){
      var reg = /^(?!0(\.0{1,2})?$)(\d(\.\d{1,2})?|10)$/;//0-10
      var priceReg = /^\d+\.?\d{0,2}$/; // 2位小数
      var regPos = /^[1-9]([0-9]*)$/; // 非负整数
      if(!regPos.test(row.storeChannelLimit)){
        this.$message({ message: "店铺限购只能输入正整数", type: "error" });
        return false;
      }
      if(!regPos.test(row.userChannelLimit)){
        this.$message({ message: "个人限购只能输入正整数", type: "error" });
        return false;
      }
      if(Number(row.storeChannelLimit) > Number(row.reserveNum)){
        this.$message({ message: "店铺库存大于店铺限购", type: "error" });
        return false;
      }
      if(Number(row.userChannelLimit) > Number(row.storeChannelLimit)){
        this.$message({ message: "店铺限购大于个人限购", type: "error" });
        return false;
      }
      return true;
    },
  },
  mounted() {
    this.materialQueryTree();
    this.queryTagList();
    this.getTagCategoryList();
    //当前登录用户身份为母平台才获取子平台列表
    if (this.deptType == 0) {
      this.getChildList();
    }
  },
  watch: {}
};
</script>

<style scoped lang="scss">
  @import '../../../assets/css/public.scss';
.vt{
  /deep/ .el-form-item__content{
    vertical-align: top !important;
  }
}
.create_stepOne .disCountSet.disCountSetTwo .el-form-item /deep/ .el-form-item__content .el-input .el-input__inner{
  width: 80px;
}
.activityDesc{
  /deep/ .el-form-item__content{
    vertical-align: top !important;
  }
}
.disCountSet {
  overflow: hidden;
}
.addDiscount {
    float: left;
  }
.vt{
  /deep/ .el-form-item__content{
    vertical-align: top !important;
  }
}
.title{
  padding-left: 35px !important;
}
.desc{
  padding-left: 35px !important;
}
.lh32{
  line-height: 32px;
}
.mr10{
  display: inline-block;
  margin-right: 10px;
}
.uptoadd{
  vertical-align: middle !important;
  /deep/ .el-input{
    width: auto !important;
  }
  .radioAlignmentSpecial{
    line-height: 32px;
  }
}
.cb{
  color: #2F4554;
}
.one{
  width: auto !important;
}
.m_l10{
  margin-left: 10px;
}
.f-r{
  float: right;
  /deep/ .el-input{
    width: auto;
  }
}
.m_r20{
  margin-right: 20px;
}
.m_r30{
  margin-right: 30px;
}
.radioAlignmentSpecial{
  line-height: 32px;
}
</style>
